package com.xianggu.designMode.chainMethod.demo03;

public abstract class OrderHandler  {
    protected OrderHandler nextHandler; // 下一处理节点
    
    // 链式设置下一节点
    public OrderHandler setNext(OrderHandler next) {
        this.nextHandler = next;
        return nextHandler;
    }

    // 模板方法定义处理流程
    public final OrderResult handle(Order order) {
        OrderResult result = doHandle(order);
        if (!result.isSuccess()) return result;
        if (nextHandler != null) return nextHandler.handle(order);
        return OrderResult.success();
    }

    // 抽象方法：具体校验逻辑由子类实现
    protected abstract OrderResult doHandle(Order order);
}